package ywh.model
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * 背景
	 * @author ywh
	 */
	public class Model2BackGround extends Sprite
	{
		public var builderInfoBtn:MovieClip;
		public var homeBtn:MovieClip;
		public var listBtn:MovieClip;
		public var mapBtn:MovieClip;
		public var thinkBtn:MovieClip;
		private var _model2:Model2;
		internal var title:Loader;
		
		public function Model2BackGround()
		{
			title = new Loader();
			title.x = 130;
			title.y = 35;
			addChildAt(title, 2);
		}
		
		internal function startSync():void
		{
			_model2 = parent as Model2;
			initShow();
			initEvent();
		}
		
		private function initShow():void
		{
			listBtn.gotoAndStop("off");
			thinkBtn.gotoAndStop("off");
		
		}
		
		private function initEvent():void
		{
			homeBtn.buttonMode = true;
			homeBtn.mouseChildren = false;
			mapBtn.buttonMode = true;
			mapBtn.mouseChildren = false;
			builderInfoBtn.buttonMode = true;
			builderInfoBtn.mouseChildren = false;
			thinkBtn.buttonMode = true;
			thinkBtn.mouseChildren = false;
			listBtn.buttonMode = true;
			listBtn.mouseChildren = false;
			this.addEventListener(MouseEvent.MOUSE_DOWN, this_mouseDown);
		}
		
		private function this_mouseDown(e:MouseEvent):void
		{
			switch (e.target)
			{
				case homeBtn: 
					_model2.otherInfoProvider["home_handle"]();
					break;
				case mapBtn: 
					_model2.otherInfoProvider["map_handle"]();
					break;
				case builderInfoBtn: 
					_model2.addChild(_model2.builderInfo);
					e.stopImmediatePropagation();
					break;
				case thinkBtn: 
					if (_model2.thinkPanel.parent)
					{
						_model2.removeChild(_model2.thinkPanel)
					}
					else
					{
						_model2.addChild(_model2.thinkPanel);
					}
					e.stopImmediatePropagation();
					break;
				case listBtn: 
					if (_model2.listPanel.parent)
					{
						_model2.removeChild(_model2.listPanel)
					}
					else
					{
						_model2.addChild(_model2.listPanel);
					}
					e.stopImmediatePropagation();
					break;
			}
		
		}
	
	}

}